﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using AlibabaCloud.SDK.Alidns20150109.Models;
using TencentCloud.Dnspod.V20210323.Models;
using TencentCloud.Common;
using TencentCloud.Dnspod.V20210323;

namespace xrwang.DDNS
{
    /// <summary>
    /// 域名记录信息
    /// </summary>
    public class DomainRecordInfo
    {
        /// <summary>
        /// 记录id
        /// </summary>
        public string RecordId { get; set; }
        /// <summary>
        /// 域名名称
        /// </summary>
        public string DomainName { get; set; }
        /// <summary>
        /// 主机记录
        /// </summary>
        public string RR { get; set; }
        /// <summary>
        /// 记录类型
        /// </summary>
        public string Type { get; set; }
        /// <summary>
        /// 记录值
        /// </summary>
        public string Value { get; set; }
        /// <summary>
        /// 解析生效时间
        /// </summary>
        public long? TTL { get; set; }
        /// <summary>
        /// 优先级
        /// </summary>
        public long? Priority { get; set; }
        /// <summary>
        /// 解析线路
        /// </summary>
        public string Line { get; set; }
        /// <summary>
        /// 锁定状态
        /// </summary>
        public bool? Locked { get; set; }
        /// <summary>
        /// 状态
        /// </summary>
        public bool Status { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public DomainRecordInfo()
        { }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="recordId">记录id</param>
        /// <param name="domainName">域名名称</param>
        /// <param name="rr">主机记录</param>
        /// <param name="type">记录类型</param>
        /// <param name="value">记录值</param>
        /// <param name="ttl">解析生效时间</param>
        /// <param name="priority">优先级</param>
        /// <param name="line">解析线路</param>
        /// <param name="locked">锁定状态</param>
        /// <param name="status">状态</param>
        public DomainRecordInfo(string recordId, string domainName, string rr, string type, string value,
            long? ttl, long? priority, string line, bool? locked, bool status)
        {
            RecordId = recordId;
            DomainName = domainName;
            RR = rr;
            Type = type;
            Value = value;
            TTL = ttl;
            Priority = priority;
            Line = line;
            Locked = locked;
            Status = status;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="recordInfo">腾讯云域名记录信息</param>
        public DomainRecordInfo(RecordInfo recordInfo)
            : this(recordInfo.Id.HasValue ? recordInfo.Id.Value.ToString() : "", "", recordInfo.SubDomain, recordInfo.RecordType, recordInfo.Value,
                  recordInfo.TTL.HasValue ? (long)recordInfo.TTL.Value : null, recordInfo.MX.HasValue ? (long)recordInfo.MX.Value : null, recordInfo.RecordLine, null, recordInfo.Enabled == 1)
        { }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="response">阿里云域名记录信息</param>
        public DomainRecordInfo(DescribeDomainRecordInfoResponseBody body)
            : this(body.RecordId, body.DomainName, body.RR, body.Type, body.Value,
                  body.TTL.HasValue ? body.TTL.Value : null, body.Priority.HasValue ? body.Priority.Value : null, body.Line, body.Locked, body.Status == Aliyun.DomainRecordStatusEnum.Enable.ToString("g"))
        { }

        /// <summary>
        /// 返回字符串
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format("域名记录信息：{0}记录id：{1}{0}域名：{2}{0}主机记录：{3}{0}记录类型：{4}{0}记录值：{5}{0}" +
                "解析生效时间：{6}秒{0}优先级：{7}{0}解析线路：{8}{0}锁定状态：{9}{0}状态：{10}",
                Environment.NewLine, RecordId, DomainName, RR, Type, Value,
                TTL, Priority, Line, Locked, Status);
        }
    }
}